package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {
    @Autowired
    private IWmChannelService channelService;
    /**
     * 分页查询频道
     * 请求路径：/list
     * 请求方式：POST
     * 参数：
     *      ChannelDto
     * 响应结果：
     *      ResponseResult
     */
    @PostMapping("list")
    @ApiOperation(value = "分页查询频道",notes = "author:xdl")
    @ApiImplicitParam(name ="dto" ,value = "频道查询对象",required = true,dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto){

        return channelService.listByName(dto);
    }

    /**
     * 频道新增
     * 请求路径：
     * 请求方式：POST
     * 参数：
     *      WmChannel
     * 响应结果：
     *      ResponseResult
     */
    @PostMapping
    @ApiOperation(value = "频道新增",notes = "author:xdl")
    @ApiImplicitParam(name ="wmChannel" ,value = "频道对象",required = true,dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        return channelService.saveChannel(wmChannel);
    }
    /**
     * 查询所有的频道
     * 请求路径：/channels
     * 请求方式：GET
     * 参数：
     *
     * 响应结果：
     *      ResponseResult
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        List<WmChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }
}
